import { RetailFundType } from '../common/retailDefinition.js';
import { FundAccount } from '../funds/fundAccount.js';
export class RetailFundAccount {
    // 零售账户类型
    constructor(fundType, fundAccount) {
        this.fundType = fundType;
        this.fundAccount = fundAccount;
    }

    // 序列化为 JSON
    _$RetailFundAccountToJson() {
        let ret = {};
        ret["fundType"] = this.fundType.code;  // 
        ret["fundAccountId"] = this.fundAccount ? this.fundAccount.id : null;
        return ret;
    }

    toJson() {
        return this._$RetailFundAccountToJson();
    }

    // 从 JSON 反序列化
    static retailFundAccountFromJson(json) {
        try {
            // 假设 fundType 是一个整数索引，可以直接映射为枚举类型
            let type = RetailFundType.fromCode(json["fundType"]);

            let fundAccount = null;
            if (json["fundAccount"] !== null) {
                fundAccount = FundAccount.fromJson(json["fundAccount"]);
            }

            return new RetailFundAccount(type, fundAccount);
        } catch (err) {
            console.log("Convert jsonToRetailFundAccount failed:", err);
            return null;
        }
    }
}